package com.lagou.edu.blog.controller;

import com.lagou.edu.blog.pojo.Article;
import com.lagou.edu.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping
    public ModelAndView getList(@RequestParam(required = false) Integer pageNumber,
                                @RequestParam(required = false) Integer pageSize) {

        Page<Article> articlePage = articleService.getList(pageNumber, pageSize);

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("articlePage", articlePage);
        modelAndView.setViewName("client/index");

        return modelAndView;
    }
}
